package controller

import (
	"fmt"
	"gin_maker_chat/client/handler"
	"net/http"

	"github.com/gin-gonic/gin"
)

func RegisterIndexController(ctx *gin.Context) {

	//获取用户名和密码err
	usercode := ctx.PostForm("userCode")
	username := ctx.PostForm("userName")
	userNick := ctx.PostForm("nickName")
	password := ctx.PostForm("passWord")
	fmt.Println("用户编码：x,用户账号：y,用户昵称：z,用户密码 :a", usercode, username, userNick, password)
	//如果验证通过，连接到服务器
	userHandler := &handler.UserHandler{}
	err := userHandler.Register(usercode, username, userNick, password)
	if err != nil {
		fmt.Println("注册失败，err=", err)
		ctx.HTML(http.StatusOK, "auth-register.html", gin.H{
			"err": err,
		})
		return
	} else {
		fmt.Println("注册成功")
		ctx.Redirect(302, "/login")
	}

}
